package com.kgc.bigdata.spark.core

import org.apache.spark.{SparkConf, SparkContext}

/**
  * Spark Core实现WordCount统计
  */
object WordCount {
  def main(args: Array[String]) {
    val sparkConf = new SparkConf
    sparkConf.setAppName("WordCount")
    val sc = new SparkContext(sparkConf)

    val textFile = sc.textFile(args(0))
    val wordCounts = textFile.flatMap(line => line.split("\t")).map((word => (word, 1))).reduceByKey(_ + _)

    //将执行结果输出到控制台上，便于观察
    //wordCounts.collect.foreach(println)

    //调整一：将数据输出到文件系统
    wordCounts.saveAsTextFile(args(1))

    sc.stop()
  }
}
